//
//  TTURLImageLoader.h
//  Tint
//
//  Created by Kevin Wu on 3/12/12.
//  Copyright (c) 2012 Telligenty. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "Core/Core.h"
#import "Additions/Additions.h"

#import "TTDiskCache.h"
#import "Network/TTHTTPRequest.h"


#define TTURLImageCacheName @"URLImage"



@interface TTURLImageLoader : NSObject<TTOperationDelegate> {
    NSTimeInterval _defaultCacheTimeoutInterval;
    NSMutableDictionary *_downloadItemMap;
}

@property(nonatomic, assign) NSTimeInterval defaultCacheTimeoutInterval; // Default: 7 days


+ (TTURLImageLoader *)sharedObject;
+ (BOOL)hasSharedObject;
+ (void)destroySharedObject;


- (void)loadImageWithAddress:(NSString *)address;

- (void)loadImageWithAddress:(NSString *)address 
        cacheTimeoutInterval:(NSTimeInterval)cacheTimeoutInterval // <=0 for default
                      target:(id)target 
                     success:(SEL)success 
                     failure:(SEL)failure 
                failureImage:(UIImage *)failureImage;



- (void)cancelDownloadingAddress:(NSString *)address;
- (void)cancelRequestingTarget:(id)target;

- (BOOL)isAddressDownloading:(NSString *)address;
- (BOOL)isTargetRequesting:(id)target;

+ (NSString *)cacheKeyFromAddress:(NSString *)address;
- (void)removeCachedFileOfAddress:(NSString *)address;

@end


@protocol TTURLImageLoaderTargetProtocol <NSObject>
- (BOOL)imageLoading;
- (void)setImageLoading:(BOOL)loading;
@end

